﻿namespace Furesoft.Styling.Design
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using FastColoredTextBoxNS;

    public class UnderlineColorStyle : FastColoredTextBoxNS.Style
    {

        List<string> colors;

        public UnderlineColorStyle()
        {
            colors = new List<string>(Enum.GetNames(typeof(KnownColor)));
        }

        public string GetColorPattern()
        {
            string s = "";

            foreach (var color in colors)
            {
                s += color + "|";
            }
            if (s.EndsWith("|"))
            {
                s = s.Remove(s.Length - 1, 1);
            }

            return s;
        }

        public override void Draw(Graphics gr, Point position, Range range)
        {
            //get size of rectangle
            var size = GetSizeOfRange(range);
            //create rectangle
            var rect = new Rectangle(position, size);
            var t = range.GetFragment(this, false);

            if (colors.Contains(t.Text))
            {
                var color = new Pen(Color.FromName(t.Text));

                gr.DrawLine(color, rect.X, rect.Y + rect.Height - 1, rect.X + rect.Width, rect.Y + rect.Height - 1);
                gr.DrawLine(color, rect.X, rect.Y + rect.Height, rect.X + rect.Width, rect.Y + rect.Height);
            }
        }
    }
}